{% extends "_base.html" %}

{% block main %}

<script>
  $(function () {
    $('#signinForm').submit(function (e) {
      e.preventDefault();
      var md5pw = md5( $('#password').val());
      var data = {
        username: $('#username').val(),
        password: md5pw,
        email: $('#email').val(),
        phone: $('#phone').val(),
      };
      $.ajax({
        type: 'POST',
        url: '/api/signin',
        data: JSON.stringify(data),
        success: function (resp) {
          if (resp.code === 200) {
            alert('注册成功,即将进入首页');
            location.assign('/home');
          } else {
            alert(resp.info)
          }
        },
        contentType: 'application/json',
        dataType: 'json'
      });
    });
  });
</script>

<form id="signinForm">
  <div class="form-group">
    <p id="error" class="text-danger"></p>
  </div>
  <div class="form-group">
    <label>用户名</label>
    <input id="username" type="text" class="form-control" placeholder="请输入用户名">
  </div>
  <div class="form-group">
    <label>邮箱</label>
    <input id="email" type="text" class="form-control" placeholder="请输入邮箱">
  </div>
  <div class="form-group">
    <label>手机号</label>
    <input id="phone" type="text" class="form-control" placeholder="请输入手机号">
  </div>
  <div class="form-group">
    <label>密码</label>
    <input id="password" type="password" class="form-control" placeholder="请输入密码">
  </div>
  <button type="submit" class="btn btn-outline-primary">注册</button>
</form>

{% endblock %}
